package com.itheima.service;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.apache.shiro.session.Session;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * Created by Chilly Cui on 2020/9/11.
 */
@Service
public class ShiroServiceImpl implements ShiroService {

    //属于user或者admin之一;修改logical为OR 即可
    @RequiresRoles(value = {"admin", "user"}, logical = Logical.AND)
    public void test() {
        //session一个重要的点：可以在service里面获取到session中数据
        Session session = SecurityUtils.getSubject().getSession();
        Object value = session.getAttribute("shiroSessionKey");

        System.out.println("ShiroService, time: " + new Date()+" k=v:"+value);
    }
}
